<%--
  Created by IntelliJ IDEA.
  User: 75880
  Date: 2024/8/17
  Time: 22:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>供应商管理系统</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>

<body data-type="generalComponents">
<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
            <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                    <span id="yonghuming" class="tpl-header-list-user-nick"></span><span class="tpl-header-list-user-ico"> <img
                        src="assets/img/user01.png"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="login.jsp" ><span class="am-icon-power-off" ></span> 退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
</header>
<div class="tpl-page-container tpl-page-header-fixed">
    <div class="tpl-left-nav tpl-left-nav-hover">
        <div class="tpl-left-nav-list">
            <ul class="tpl-left-nav-menu">
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list">
                        <i class="am-icon-wpforms"></i>
                        <span>企业管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu">
                        <li>
                            <a href="info-certification.jsp">
                                <i class="am-icon-angle-right"></i>
                                <span>企业信息认证</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                        <i class="am-icon-table"></i>
                        <span>供应商管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu" style="display:block">
                        <li>
                            <a href="white-list.jsp" class="active">
                                <i class="am-icon-angle-right"></i>
                                <span>供应商白名单</span>
                            </a>
                            <a href="black-list.jsp">
                                <i class="am-icon-angle-right"></i>
                                <span>供应商黑名单</span>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="tpl-content-wrapper">
        <div class="tpl-content-page-title">
            供应商白名单列表
        </div>
        <ol class="am-breadcrumb">
            <li class="am-active"><a style="color: #999999;">供应商管理</a></li>
            <li class="am-active">供应商白名单</li>
        </ol>
        <div class="tpl-portlet-components">
            <div class="tpl-block">
                <div class="am-g">
                    <div class="am-u-sm-6 am-u-md-2">
                        <div class="am-input-group am-input-group-sm">
                                <span class="am-input-group-btn">
                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px">企业名称</span>
                                </span>
                            <input type="text" class="am-form-field" value="" placeholder="&nbsp;&nbsp;请输入企业名称"
                                   style="border: 1px solid #c2cad8;border-radius: 3px;">
                        </div>
                    </div>
                    <div class="am-u-sm-6 am-u-md-3">
                        <div class="am-form-group">
                            <span style="font-size: 14px;">企业评级</span>
                            <select id="queryLevel" data-am-selected="{btnSize: 'sm'}">
                                <option value="">请选择企业评级</option>
                                <option value="1">1级</option>
                                <option value="2">2级</option>
                                <option value="3">3级</option>
                            </select>
                        </div>
                    </div>
                    <div style="float:right">
                        <div class="am-form-group">
                            <button type="button" class="am-btn am-btn-primary am-btn-sm"
                                    id="doc-prompt-toggle" value="添加供应商">添加供应商
                            </button>
                        </div>
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <form class="am-form">
                            <table class="am-table am-table-striped am-table-hover table-main">
                                <thead>
                                <tr>
                                    <th class="table-id">序号</th>
                                    <th class="table-title">企业名称</th>
                                    <th class="table-type">企业联系人</th>
                                    <th class="table-author am-hide-sm-only">联系方式</th>
                                    <th class="table-date am-hide-sm-only">联系邮箱</th>
                                    <th class="table-date am-hide-sm-only">企业评级</th>
                                    <th class="table-date am-hide-sm-only">更新日期</th>
                                    <th class="table-set">操作</th>
                                </tr>
                                </thead>
                                <tbody id="doc-modal-list">
                                <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
                                    <div class="am-modal-dialog" style="font-size: 16px;">
                                        <div class="am-modal-hd">提示</div>
                                        <div class="am-modal-bd">将供应商添加黑名单后该企业将无法在平台进行融资，是否继续？
                                        </div>
                                        <div class="am-modal-footer">
                                            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                                            <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                                        </div>
                                    </div>
                                </div>
                                </tbody>
                            </table>
                            <div class="am-cf">
                                <div class="am-fr" id="分页按钮">


                                </div>
                            </div>
                            <hr>
                        </form>
                        <!-- 添加供应商弹出框 -->
                        <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt">
                            <div class="am-modal-dialog">
                                <form action="" class="am-form am-form-horizontal">
                                    <legend style="font-size: 18px;padding: 12px 0;">添加供应商</legend>
                                    <div class="am-form-group">
                                        <label for="doc-select-1" class="am-u-sm-4 am-form-label"
                                               style="font-size: 15px;">企业名称</label>
                                        <div class="am-u-sm-6">
                                            <select id="doc-select-1" required>

                                            </select>
                                        </div>
                                        <span class="am-form-caret"></span>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="doc-select-2" class="am-u-sm-4 am-form-label"
                                               style="font-size: 15px;">统一社会信用代码</label>
                                        <div class="am-u-sm-6" style=" text-align: left;margin-top: 6px;">
                                            <span id="Social"></span>
                                        </div>
                                        <span class="am-form-caret"></span>
                                    </div>
                                    <div class="am-form-group" style="margin-bottom: 20px;">
                                        <label for="doc-select-2" class="am-u-sm-4 am-form-label"
                                               style="font-size: 15px;">企业评级</label>
                                        <div class="am-u-sm-6">
                                            <select id="doc-select-2" required>
                                                <option value="">请选择企业评级</option>
                                                <option value="1">1级</option>
                                                <option value="2">2级</option>
                                                <option value="3">3级</option>
                                            </select>
                                        </div>
                                        <span class="am-form-caret"></span>
                                    </div>
                                </form>
                                <div class="am-modal-footer" style="border-top: 1px solid #dedede;">
                                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                                    <span class="am-modal-btn" data-am-modal-confirm>提交</span>
                                </div>
                            </div>
                        </div>
                        <!-- 添加至黑名单弹出框 -->
                        <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt1">
                            <div class="am-modal-dialog">
                                <form action="" class="am-form am-form-horizontal">
                                    <legend style="font-size: 18px;padding: 12px 0;">添加至黑名单</legend>
                                    <div class="am-form-group">
                                        <label for="doc-select-1" class="am-u-sm-4 am-form-label"
                                               style="font-size: 15px;">企业名称</label>
                                        <div class="am-u-sm-6" style=" text-align: left;margin-top: 6px;">
                                            <span>腾讯科技</span>
                                        </div>
                                        <span class="am-form-caret"></span>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="doc-select-2" class="am-u-sm-4 am-form-label"
                                               style="font-size: 15px;">统一社会信用代码</label>
                                        <div class="am-u-sm-6" style=" text-align: left;margin-top: 6px;">
                                            <span>23456787657645343124567</span>
                                        </div>
                                        <span class="am-form-caret"></span>
                                    </div>
                                    <div class="am-form-group" style="margin-bottom: 20px;">
                                        <label for="doc-select-2" class="am-u-sm-4 am-form-label"
                                               style="font-size: 15px;">添加理由</label>
                                        <div class="am-u-sm-6">
                                            <textarea class="" rows="4" id="user-intro"
                                                      placeholder="请输入添加理由"></textarea>
                                        </div>
                                        <span class="am-form-caret"></span>
                                    </div>
                                </form>
                                <div class="am-modal-footer" style="border-top: 1px solid #dedede;">
                                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                                    <span id="submitBtn" class="am-modal-btn" data-am-modal-confirm>提交</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tpl-alert"></div>
        </div>
    </div>
</div>
<input type="hidden" id="account" value="<%=request.getParameter("email")%>" >
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script type="text/javascript">

    const constAccount = sessionStorage.getItem('constAccount');

    $(document).ready(function () {
        //1.初始界面展示所有白名单信息
        $.get("SupplierWhiteList/query", {"account": constAccount,"pageindex":"1"}, function (ph) {
            JSON.stringify(ph);
            show(ph.list);
            showBut(ph);
        });
        //2.按条件查询：企业名称 或者 企业评级
        $(".am-form-field").change(function () {
            var name = $(this).val();
            var level = $("#queryLevel").val();
            $.get("SupplierWhiteList/query", {"name": name, "level": level, "account": constAccount}, function (ph) {
                JSON.stringify(ph);
                show(ph.list);
                showBut(ph);
            });
        });
        $("#queryLevel").change(function () {
            var name = $(".am-form-field").val();
            var level = $(this).val();
            $.get("SupplierWhiteList/query", {"name": name, "level": level, "account": constAccount}, function (ph) {
                JSON.stringify(ph);
                show(ph.list);
                showBut(ph);
            });
        });

        //3.添加白名单
        $(document).on('click', '#doc-prompt-toggle', function () {
            $.get("SupplierWhiteList/addSupplierWhiteList", {"account": constAccount}, function (SupplierWhiteList) {
                showAdd(SupplierWhiteList);
            });
            $('#my-prompt').modal({
                relatedTarget: this,
                onConfirm: function (options) {
                    //点击确认调用函数
                    var level = $("#doc-select-2").val();
                    var empName = $("#doc-select-1").val();
                    $.get("SupplierWhiteList/AddSupplierWhiteList", {
                        "account": constAccount,
                        "level": level,
                        "empName": empName
                    }, function (boo) {
                        if (boo) {
                            alert("添加成功！");
                            $.get("SupplierWhiteList/query", {"account": constAccount}, function (ph) {
                                JSON.stringify(ph);
                                show(ph.list);
                                showBut(ph);
                            });

                        } else {
                            alert("添加失败！");
                        }
                    });
                },
                onCancel: function (e) {
                    alert("已取消！")
                }
            });
        });
    });
    //4.设为黑名单
    $(document).on("click", "[title='拉黑']", function () {
        var name = $(this).attr("id");
        var userInput = prompt("请输入拉黑的理由:");
        $.get("SupplierWhiteList/addSupplierBlackList", {
            "name": name,
            "reason": userInput,
            "account": constAccount
        }, function (boo) {
            if (boo && confirm("将供应商添加黑名单后该企业将无法在平台进行融资，是否继续？")) {
                alert("修改成功！")
                $.get("SupplierWhiteList/query", {"account": constAccount}, function (ph) {
                    JSON.stringify(ph);
                    show(ph.list);
                    showBut(ph);
                });
            } else {
                alert("已取消修改！")
            }
        });
    });

    //根据PageHelper对象，动态获得分页按钮： 首页 上一页 下一页 尾页
    function showBut(pageHelper) {
        $("#分页按钮").empty();
        if(pageHelper.indexPage!=1){
            $("<input type='button' value='首页' name='1' />").appendTo("[id = '分页按钮']");
            $("<input type='button' value='上一页' name='"+(pageHelper.indexPage-1)+"' />").appendTo("[id = '分页按钮']");
        }
        if(pageHelper.indexPage!=pageHelper.countPage){
            $("<input type='button' value='下一页' name='"+(pageHelper.indexPage+1)+"' />").appendTo("[id = '分页按钮']");
            $("<input type='button' value='尾页' name='" + pageHelper.countPage + "' />").appendTo("[id = '分页按钮']");
        }
    }
    //为分页按钮，绑定单击事件：
    $(document).on("click","[type='button'][value!='添加供应商']",function () {
        //获得下拉列表的value值：
        var level = $("#queryLevel").val();
        var name = $(".am-form-field").val();
        var pageindex=$(this).attr("name");
        $.get("SupplierWhiteList/query",{"level":level,"name":name,"pageindex":pageindex,"account":constAccount},function (ph) {
            JSON.stringify(ph);
            show(ph.list);
            showBut(ph);
        });
    });

    //展示信息的通用方法
    function show(Suppliers) {
        $("#doc-modal-list").empty();
        for (var i = 0; i < Suppliers.length; i++) {
            var selectedValue = Suppliers[i].supplierLevel;  // 从供应商对象中获取默认选中的值
            //判断供应商水平，给供应商水平下拉列表赋默认值
            var options = [
                {value: "1", text: "1级"},
                {value: "2", text: "2级"},
                {value: "3", text: "3级"}
            ];

            var optionsHtml = "";
            for (var j = 0; j < options.length; j++) {
                if (options[j].value === selectedValue) {
                    optionsHtml += "<option value=\"" + options[j].value + "\" selected>" + options[j].text + "</option>";
                } else {
                    optionsHtml += "<option value=\"" + options[j].value + "\">" + options[j].text + "</option>";
                }
            }
            $("<tr data-id=\"" + (i + 1) + "\">" +
                "    <td>" + (i + 1) + "</td>" +
                "    <td class=\"am-hide-sm-only\"><a href=\"#\">" + Suppliers[i].name + "</a></td>" +
                "    <td class=\"am-hide-sm-only\">" + Suppliers[i].idcardName + "</td>" +
                "    <td class=\"am-hide-sm-only\">" + Suppliers[i].phone + "</td>" +
                "    <td class=\"am-hide-sm-only\">" + Suppliers[i].email + "</td>" +
                "    <td class=\"am-hide-sm-only\">" +
                "        <div class=\"\">" +
                "            <select id='changeLevel' data-am-selected=\"{btnSize: 'xs'}\" name='" + Suppliers[i].name + "'>" +
                optionsHtml +
                "            </select>" +
                "        </div>" +
                "    </td>" +
                "    <td class=\"am-hide-sm-only\">" + Suppliers[i].updateDate + "</td>" +
                "    <td>" +
                "        <div class=\"am-btn-toolbar\">" +
                "            <div class=\"am-btn-group am-btn-group-xs\">" +
                "                <span title='拉黑' id='" + Suppliers[i].name + "' class=\"am-text-secondary am-icon add-to-blacklist\" style=\"margin-left: 20px;cursor:pointer\">" +
                "                    添加至黑名单" +
                "                </span>" +
                "            </div>" +
                "        </div>" +
                "    </td>" +
                "</tr>").appendTo("#doc-modal-list");
        }
    }

    //展示添加的企业的名字
    function showAdd(SupplierWhiteList) {
        $("#doc-select-1").empty();
        $("<option value=\"\"></option>").appendTo("#doc-select-1");
        for (var i = 0; i < SupplierWhiteList.length; i++) {
            $("<option title='"+ SupplierWhiteList[i].socialUniformCode+"'></option>")
                .val(SupplierWhiteList[i].name)
                .text(SupplierWhiteList[i].name)
                .appendTo("#doc-select-1");
        }
    }

    //为添加的企业名字绑定change事件
    $(document).on("change", "#doc-select-1", function () {
        var selectElement = document.getElementById("doc-select-1");
        var selectedOption = selectElement.selectedOptions[0];
        var id = selectedOption.title;
        $("#Social").text(id);
    });

    //为修改白名单的水平
    $(document).on("change", "#changeLevel", function () {
        var changeLevel = $(this).val();
        var name = $(this).attr("name");
        $.get("SupplierWhiteList/changeLevel", {
            "changeLevel": changeLevel,
            "name": name,
            "account": constAccount
        }, function (boo) {
            if (boo) {
                alert("修改评级成功！")
            } else {
                alert("修改评级失败！")
            }
        });
    });

    //修改用户名
    $(document).ready(function () {
        $.get("UserController/selectUser",{"account":constAccount},function (str) {
            JSON.stringify(str);
            var name =str.name;
            $("#yonghuming").text(name);
        });
    });

</script>
<script>
    // 添加至黑名单
    $(function () {
        $('#submitBtn').on('click', function () {
            $('#my-confirm').modal({
                relatedTarget: this,
                onConfirm: function (options) {
                    //点击确认调用函数
                    alert("点击了确认");
                },
                onCancel: function () {
                    //点击取消调用函数
                    alert("点击了取消")
                }
            });
        });
    });
    // 二次确认
    $(function () {
        $('#doc-modal-list').find('.am-icon').add('#doc-confirm-toggle').on('click', function () {
            $('#my-prompt1').modal({
                relatedTarget: this,
                onConfirm: function (options) {
                    //点击确认调用函数
                    alert("点击了确认");
                },
                onCancel: function () {
                    //点击取消调用函数
                    alert("点击了取消")
                }
            });
        });
    });

    // 添加供应商

</script>
</body>

</html>
